﻿using System.Diagnostics.CodeAnalysis;

namespace DimensionsHelper.Serialization.Constants;


/// <summary>
/// 标记在生成常量字段的类型上
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class ConstantsClassAttribute : Attribute
{

    public ConstantsClassAttribute(Type resourcesType, Type sourceType, Type targetType)
    {
        ResourcesType = resourcesType;
        SourceType = sourceType;
        TargetType = targetType;
    }


    /// <summary>
    /// 资源类类型
    /// </summary>
    public Type ResourcesType { get; }


    /// <summary>
    /// 原始资源类型
    /// </summary>
    public Type SourceType { get; }


    /// <summary>
    /// 生成字段的目标类型
    /// </summary>
    public Type TargetType { get; }


    /// <summary>
    /// 用于验证资源字段名是否有效的正则表达式，如果此属性是<see langword="null"/>，
    /// 所有字段视为有效。
    /// </summary>
    [StringSyntax(StringSyntaxAttribute.Regex)]
    public string? Validator { get; set; }


    /// <summary>
    /// 用于匹配生成属性名的正则表达式。
    /// </summary>
    [StringSyntax(StringSyntaxAttribute.Regex)]
    public string? NameMatcher { get; set; }


    /// <summary>
    /// 创建目标类型的对象的方法名，此方法类型需要是 TTarget Method(string fieldName, TSource fieldValue)，
    /// 同时需要是静态方法。
    /// </summary>
    public string? Creator { get; set; }

}
